package com.shanwen.shopping.adapter;

import android.content.Context;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonAdapter;
import com.shanwen.shopping.R;
import com.shanwen.shopping.entity.GoodsClassify;

import java.util.List;

/**
 * 商品分类适配器
 */
public class ClassifyAdapter extends CommonAdapter<GoodsClassify> {
    private Context mContext;
    public ClassifyAdapter(Context context, int layoutResId, List<GoodsClassify> data) {
        super(context, layoutResId, data);
        this.mContext = context;
    }

    @Override
    public void onUpdate(BaseAdapterHelper helper, GoodsClassify item,int position) {
        final boolean hasSelected = helper.getPosition()==selectedPosition;
        helper.setText(R.id.classify_item_name,item.getName())
                .setTextColor(R.id.classify_item_name,
                        mContext.getResources().getColor(hasSelected ? R.color.colorAccent : R.color.primary_text))
                .setImageResource(R.id.classify_item_right_iv,hasSelected ?
                R.mipmap.ic_access_select : R.mipmap.ic_access_normal);
    }

    public int selectedPosition = 0;
    public void setSelectedItem(int position){
        selectedPosition = position;
        notifyDataSetChanged();
    }
}
